import request from '@/utils/request'
import fileAPI from '@/utils/fileAPI'

/**
 * 获取字典选择框数据
 * @param data
 * @returns {*}
 */
export function getDictSelects(data) {
  return request({
    url: '/system/dict/data/type/' + data,
    method: 'get'
  })
}

export function download(data) {
  return request({
    url: '/download',
    method: 'get',
    params: {
      fileName: data
    }
  })
}

/**
 * 通过表明 , 字段名 , 获取编码规则
 * @param data
 * @returns {*}
 */
export function getRuleCode(tableName, columnName) {
  return request({
    url: '/system/rules/checkSame/' + tableName + '/' + columnName,
    method: 'get'
  })
}

/**
 * @Author wssn
 * @Description  保存页面设置
 * @Date 9:51 2022/5/5
 **/
export function savePageSettings(data) {
  return request({
    url: '/system/sys/showField/addOrEdit',
    method: 'post',
    data: data
  })
}
/**
 * @Author wssn
 * @Description  删除页面设置
 * @Date 19:03 2022/5/26
 **/
export function backDefault(data) {
  return request({
    url: '/system/sys/showField/deleteByUserIdAndPageIdAndCompanyId',
    method: 'post',
    data: data
  })
}
/**
 * @Author wssn
 * @Description  获取页面设置
 * @Date 9:52 2022/5/5
 **/
export function getPageSettings(data) {
  return request({
    url: '/system/sys/showField/getByPageId',
    method: 'post',
    data: data
  })
}
export function getPagePushSettings(data) {
  return request({
    url: '/system/emailPush/moduleName',
    method: 'post',
    data: data
  })
}
export function savePagePushSettings(data) {
  return request({
    url: '/system/emailPush/addOrEdit',
    method: 'post',
    data: data
  })
}
export function pushFlagChange(data) {
  return request({
    url: '/system/emailPush/cancelPush',
    method: 'post',
    data: data
  })
}

export function fileUpload(files) {
  const formData = new FormData()
  for (let i = 0; i < files.length; i++) {
    formData.append('files', files[i], files[i].name)
  }
  return fileAPI({
    url: '/resource/uploads',
    method: 'post',
    data: formData
  })
}

/**
 * @Author wssn
 * @Description  定时获取版本号，如果版本号变了，刷新页面
 * @Date 13:47 2022/10/25
 **/
export function getSystemVersion(data) {
  return request({
    url: '/iot/iot/screen/isUpdate',
    method: 'post',
    data: data
  })
}
export function getPool(data) {
  return request({
    url: '/points/pool/' + data,
    method: 'get'
  })
}
